package com.mz.hotel.system;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mz.hotel.manage.entiy.Admin;
import com.mz.hotel.until.ATTSystem;

public class SessionFilter  implements Filter{

	@Override
	public void destroy() {
		
	}

	@Override
	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain )
			throws IOException, ServletException {
		HttpServletRequest request=(HttpServletRequest)servletRequest;
		HttpServletResponse response=(HttpServletResponse)servletResponse;
		
		Admin admin=ATTSystem.getSessionAdmin(request);
		
		String uri=request.getRequestURI();
		if(admin==null){
			if(uri.equals("/manage/login.jsp") || uri.equals("/servlet/adminServlet")){
				chain.doFilter(request, response);
			}else{
				response.sendRedirect("/manage/login.jsp");
			}
		}else{
			chain.doFilter(request, response);
		}
		

	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		
	}

	
	

}
